<!-- Add/Edit Project -->
<div class="content" id="projects_edit">
	<h2>Project</h2>
	<div class="box">
		<form onsubmit="return projects_edit_submit();">
			<input type="hidden" name="id" value=""/>
			<b>Name</b>
			<input type="text" name="name" value=""/>
			<br/>
			<br/>
			<b>Project Members</b><br/>
			<hr/>
			<div id="projects_edit_members"><center><b>Loading</b></center></div>
			<br style="clear: both;"/>
			<hr/>
			<br/>
			<b>Description</b><br/>
			<textarea name="description" cols="70" rows="10"></textarea>
			<br/>
			<center><input type="submit" value="Submit"/></center>
		</form>
	</div>

	<script>
		function projects_edit_loader(env, id){
			env.models.Project.get(id, function(project){
				$("#projects_edit input[@name='name']").val(project.name);
				$("#projects_edit input[@name='id']").val(project.id);
				$("#projects_edit textarea[@name='description']").val(project.description);
				$("#projects_edit input[@type='checkbox']").attr('checked', false);
				for(var x=0; x < project.members.length; x++){
					var m = project.members[x];
					$("#projects_edit input[@type='checkbox'][@value='" + m.id + "']").attr('checked', true);
				}
			});
		}

		function projects_edit_submit(){
			var project = {
				name: $("#projects_edit input[@name='name']").val(),
				description: $("#projects_edit textarea[@name='description']").val(),
				members: [],
			};
			$("#projects_edit input[@name='members']").each(function(){
				if(this.checked){
					project.members.push({ id: this.value, className: "boto_web.resources.user.User"});
				}
			});
			var id = $("#projects_edit input[@name='id']").val();
			boto_web.save("data/projects/" + id, project);
			loadPage("#projects");
			return false;
		}
		$(".content#projects_edit").bind("load", projects_edit_loader);
	</script>
</div>
<!-- /Add/Edit Project -->
